package com.my.blog.website.service.impl;

import cn.hutool.core.util.StrUtil;
import com.my.blog.website.dao.QuestionCategoryVoMapper;
import com.my.blog.website.dao.QuestionVoMapper;
import com.my.blog.website.modal.Vo.QuestionCategoryVo;
import com.my.blog.website.modal.Vo.QuestionCategoryVoExample;
import com.my.blog.website.modal.Vo.QuestionVo;
import com.my.blog.website.service.IQuestionCategoryService;
import com.my.blog.website.service.IQuestionService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Description 问答分类服务实现
 * @ClassName QuestionCategoryServiceImpl
 * @Author gyh
 * @date 2020.08.11 17:35
 */
@Service
public class QuestionCategoryServiceImpl implements IQuestionCategoryService {
    @Resource
    QuestionCategoryVoMapper questionCategoryVoMapper;


    @Override
    public List<QuestionCategoryVo> getQuestionlist(String categoryName) {
        QuestionCategoryVoExample example = new QuestionCategoryVoExample();
        QuestionCategoryVoExample.Criteria criteria = example.createCriteria();
        if (StrUtil.isNotEmpty(categoryName)) {
            criteria.andCategoryLike("%" + categoryName + "%");
        }
        List<QuestionCategoryVo> questionCategoryVos = questionCategoryVoMapper.selectByExample(example);
        return questionCategoryVos;
    }

    @Override
    public QuestionCategoryVo getById(Integer categoryId) {
        return questionCategoryVoMapper.selectByPrimaryKey(categoryId);
    }
}
